package io;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import cn.hutool.extra.mail.MailAccount;
import cn.hutool.extra.mail.MailUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.security.KeyPair;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

@RunWith(SpringJUnit4ClassRunner.class)
//@SpringBootTest(classes = MyaApplication.class)
public class test {

    @Test
    public void test8() {
                MailAccount account = new MailAccount();
                account.setHost("smtpdm.aliyun.com"); //smtp 服务器地址
                account.setPort(25);	//端口
                account.setFrom("hm@hm-jr.com"); // 发信人
                account.setUser("hm@hm-jr.com"); //账号
                account.setPass("LuoYangMail123"); //密码

                String content = "1111";
                //发送邮件
                MailUtil.send(account, "1842052397@qq.com", "afsdfasdfasd", content, true);
    }
    @Test
    public void test7() {
        System.out.println(RandomUtil.randomString(10));
    }

    @Test
    public void test6() {
        Long timestamp = Long.parseLong("1512172799000") ;
        String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA).format(new Date(timestamp));
        System.out.println(date);

//        Long timestamp = Long.parseLong("1512172799000");
        String s = new java.text.SimpleDateFormat("yyyy MM-dd HH:mm:ss").format(new java.util.Date (timestamp));
        System.out.println(s);



//        String date = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date(timestamp));
//        System.out.println(date);
    }

//    @Autowired
//    private RedisTemplate redisTemplate;
//    @Autowired
//    private StringRedisTemplate stringRedisTemplate;

    @Test
    public void test5(){
        System.out.println(RandomUtil.randomString(12));
    }

    @Test
    public void genRSAPublicKeySpecTest1111() {
        KeyPair pair = SecureUtil.generateKeyPair("RSA");
        byte[] privateKey = pair.getPrivate().getEncoded();
        byte[] publicKey = pair.getPublic().getEncoded();

        RSA rsa = SecureUtil.rsa(privateKey, publicKey);

        // 公钥加密，私钥解密
        byte[] encrypt = rsa.encrypt(StrUtil.bytes("111111", CharsetUtil.CHARSET_UTF_8), KeyType.PublicKey);
        byte[] decrypt = rsa.decrypt(encrypt, KeyType.PrivateKey);

        System.out.println("_______");
        //加密byte
        System.out.println(encrypt);
        //解密byte
        System.out.println(decrypt);
        //解密byte 后转字符串 解出密码
        System.out.println(StrUtil.str(decrypt, CharsetUtil.CHARSET_UTF_8));
        System.out.println("_______");
//
//
//
    }

//    @Test
//    public void testredis(){
//        //鍐欏叆鏁版嵁
////        String bigkey = RedisKey.BIT;
//        String bigkey = "candy party";
//        String key = "candyCn";
//        String value = "验证码有效时间1分钟，请您尽快完成验证领取糖果！";
//
//        String key2 = "candyEn";
//        String value2 = "verification code valid for 3 minutes.pease input the code soon in case to get the candy.";
//
//        String key3 = "candyCnHead";
//        String value3 = "糖果code:";
//
//        String key4 = "candyEnHead";
//        String value4 = "moltose code";
//        stringRedisTemplate.opsForHash().put(bigkey,key,value);
//        stringRedisTemplate.opsForHash().put(bigkey,key2,value2);
//
//        stringRedisTemplate.opsForHash().put(bigkey,key3,value3);
//        stringRedisTemplate.opsForHash().put(bigkey,key3,value3);
//
//        stringRedisTemplate.opsForHash().put(bigkey,key4,value4);
//        stringRedisTemplate.opsForHash().put(bigkey,key4,value4);
//
//        String s1 = (String) stringRedisTemplate.opsForHash().get(bigkey,"candyCn");
//        String s2 = (String) stringRedisTemplate.opsForHash().get(bigkey,"candyEn");
////        stringRedisTemplate.expire(bigkey,10000,TimeUnit.SECONDS);
//        System.out.println(s1);
//        System.out.println(s2);
//    }
//
//    @Test
//    public void testredis1(){
//        //鍐欏叆鏁版嵁
////        String bigkey = RedisKey.BIT;
//        String bigkey = "test111";
//        String key = "2017-01-01 14:00:00";
//        //鏀惧叆鎴戜滑鎺ュ彛鐨凧SON 鏁版嵁灏辨槸
//        String value = "11";
////        stringRedisTemplate.opsForHash().put(bigkey,key,value);
//        String s = (String) stringRedisTemplate.opsForHash().get(bigkey,"2017-01-01 14:00:00");
//
//        System.out.println(s+"________");
//    }



//    /**
//     * 娴嬭瘯杩囨湡鏈哄埗
//     */
//    @Test
//    public void testredis1(){
//        //鍐欏叆鏁版嵁
////        String bigkey = RedisKey.BIT;
//        String bigkey = "test";
//        String key = "2017-01-01";
//        //鏀惧叆鎴戜滑鎺ュ彛鐨凧SON 鏁版嵁灏辨槸
//        String value = "[{\"Symbol\":\"BSbtcusd\",\"Name\":\"姣旂壒甯佺編鍏僜",\"Date\":\"2017-11-24 00:29:00\",\"Open\":\"8160.51\",\"Low\":\"8160.01\",\"High\":\"8162.99\",\"Close\":\"8160.01\",\"Volume\":\"1.88625\",\"Amount\":\"15393.4\"}]";
//        stringRedisTemplate.opsForHash().put(bigkey,key,value);
//        stringRedisTemplate.expire("test",  20, TimeUnit.SECONDS);
//
////        String s = (String) stringRedisTemplate.opsForHash().get(bigkey,"2017-01-01 14:00:00");
//
//
////        stringRedisTemplate.expire()
//
//    }
//    @Test
//    public void test() throws JSONException {
//        String str = "u=wstock01&p=wstock02&timestamp=1414597267&key=wstock";
//        String sha1 = Encrypt(str, "SHA-1");
//        //浣跨敤DigestUtils鐨勬柟娉曠粨鏋滀竴鏍�
//        String sha1Str = DigestUtils.sha1Hex(str);
//        System.out.println(sha1Str);
//        System.out.println(sha1.toLowerCase());
//        String result1 = HttpUtil.get("http://db2015.wstock.cn/wsDB_API2/stock.php?" +
//                "market=BS&query=*&u=test&p=8e6a&r_type=2",
//                "UTF-8");
//        //姝ｅ父杩斿洖
//        System.out.println(result1);
//        //璇锋眰url
//        //http://db2015.wstock.cn/wsDB_API2/stock.php?market=BS&query=*&u=test&p=8e6a&r_type=2
//        //鍔犲瘑鍚�
//        long timestamp = System.currentTimeMillis(); //鏃堕棿鎴�
//        String signature = DigestUtils.sha1Hex("u=testsha1&p=testsha1&timestamp="+timestamp+"&key=wstock");
//        //鎷艰璇锋眰url
//        String requestUrl = "http://db2015.wstock.cn/wsDB_API2/stock.php?market=BS&r_type=2&query=*&timestamp="+timestamp+"&u=testsha1&signature="+signature;
//        String result2 = HttpUtil.get(requestUrl,
//                "UTF-8");
//        //浣跨敤瀹夊叏妯″紡
//        System.out.println("姝ｅ紡"+result2);
//
//        JSONArray myJsonArray = new JSONArray(result2);
//        for(int i=0 ; i < myJsonArray.length() ;i++){
//            JSONObject myjObject = myJsonArray.getJSONObject(i);
//            System.out.println(myjObject.getString("Name"));
//        }
//
//    }
//    @Test
//    public void  test1(){
//        String url = "http://localhost:8091/api-open/v1/load_cami_info.json";
//        long timestamp = 1442198292L; //鏃堕棿鎴�
//        String body = "{\"code\" : \"89717EC914B96PF0N7S8\",\"timestamp\":\""+timestamp+"\",\"nonceStr\":\"TWSm66\",\"sign\":\"4772CD162BD317C0D99CA4AAAC88DB44\"}";
//        HttpResponse hr = HttpRequest.post(url).body(body,"application/json").execute();
//        Console.log(hr.body());
//        System.out.println(timestamp);
//
//    }
//
//    @Test
//    public void  test2(){
//        String url = "http://localhost:8091/api-open/v1/load_cami_info.json";
//        String code = "89717EC914B96PF0N7S8";
//        Long timestamp =1442198292L; //System.currentTimeMillis();
//        String nonceStr = "TWSm66";
//        String key = "Zpuj8xfvb8jltBkcDvALFcEtWvgXGdxj";
//
//        HashMap<String, String> params = new HashMap<String, String>();
//        params.put("code", code);
//        params.put("key", key);
//        params.put("timestamp", "1442198292");
//        params.put("nonceStr", nonceStr);
////        System.out.println(SignUtil.getSignature(params,"0"));
//        String sign = SignUtil.getSignature(params,"0");
//        params.put("sign",sign);
//
//        com.xiaoleilu.hutool.json.JSONObject t = JSONUtil.parseFromMap(params);
////        System.out.println("______");
////        System.out.println(t.toString());
//        String body = t.toString();
//        HttpResponse hr = HttpRequest.post(url).body(body,"application/json").execute();
//        Console.log(hr.body());
//
//
//
//
//
//    }
//    @Test
//    public void test4(){
////        String urls = "https://file.geeker.com.cn/uploadfile/ptisp/img/1508918356098/9FB9314E7AEE753919DA53EAD2C042B9.png,https://file.geeker.com.cn/uploadfile/ptisp/img/1509003266602/60E55625BC0C37C170F6CA94F7E531DE.png";
////        if (urls.indexOf(",") > 0){
////            for (int i = 0; i < urls.split(",").length; i++) {
////                System.out.println(urls.split(",")[i]);
////            }
////        }else{
////            System.out.println("--");
////        }
//
//        String s = "https://file.geeker.com.cn/uploadfile/ptisp/img/1508924234149/yangmei.png";
//        String picName = s.substring(s.lastIndexOf("/") + 1, s.length());
//        System.out.println(picName);
//    }
//
//
//    /**
//     * 鐭俊鎺ュ彛瀵规帴
//     */
//    @Test
//    public void test5(){
//        //docResult娉ㄥ唽鐪嬫瘡涓弬鏁板搱銆侫PI鏂囨。閲岄潰鏈夛紝姣忎釜鍙傛暟銆傘�傛斁鍦ㄤ竴涓被閲岄潰缁熶竴璋冪敤銆�
//        //鍏朵粬鎺ュ彛閮藉樊涓嶅銆傘�傜洿鎺ュ彂璇锋眰銆傜劧鍚庤幏鍙栧弬鏁帮紝鍒ゆ柇缁撴灉銆傝浆鎴恓son瀛楃涓�
//        String url ="http://121.43.192.197:8888/sms.aspx?action=send&userid=1751&account=luoyang888&password=zxc445204&mobile=13568845471&content=銆怉AAAAAA銆戞祴璇�0020";
//        //String result2 = HttpUtil.post(url,
//              //  "UTF-8");
//        //System.out.println(result2);
//        String xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><returnsms>\n" +
//                " <returnstatus>Success</returnstatus>\n" +
//                " <message>ok</message>\n" +
//                " <remainpoint>3972</remainpoint>\n" +
//                " <taskID>10402399</taskID>\n" +
//                " <successCounts>1</successCounts></returnsms>";
//        System.out.println(Xml2JsonUtil.xml2JSON(xml));
//
//
//
//
//    }
//
//    private static String Encrypt(String strObj,String encName){
//        String resultString = "";
//        try {
//            MessageDigest md = MessageDigest.getInstance(encName);
//            resultString = byteToString(md.digest(strObj.getBytes("UTF-8")));
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return resultString;
//    }
//
//    private static String byteToString(byte[] bByte) {
//        StringBuffer sBuffer = new StringBuffer();
//        for (int i = 0; i < bByte.length; i++) {
//            sBuffer.append(byteToArrayString(bByte[i]));
//        }
//        return sBuffer.toString();
//    }
//
//    private static String byteToArrayString(byte bByte) {
//        String[] strDigits = { "0", "1", "2", "3", "4", "5", "6", "7", "8",
//                "9", "A", "B", "C", "D", "E", "F" };
//        int iRet = bByte;
//        if (iRet < 0) {
//            iRet += 256;
//        }
//        int iD1 = iRet / 16;
//        int iD2 = iRet % 16;
//        return strDigits[iD1] + strDigits[iD2];
//    }
//
//    @Test
//    public void test3(){
//        System.out.println(GenNumbersUtil.genCaiMi());
//    }


}